package com.upcode.weighing.vo.req.pc;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Data
@EqualsAndHashCode(callSuper=false)
public class CorporateTransferPayReqVo {

    /**
     * 补费单位名称
     */
    private String companyName;

    /**
     * 转账开始日期
     */
    private String transferStratTime;
    /**
     * 转账结束日期
     */
    private String transferEndTime;
    /**
     * 登记人姓名
     */
    private String registrantName;
    /**
     * 登记开始日期
     */
    private String registrantStartTime;
    /**
     * 登记结束日期
     */
    private String registrantEndTime;

    public String checkParams(){
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if(StringUtils.isNotBlank(transferStratTime) && StringUtils.isBlank(transferEndTime)){
            LocalDate nowDate = LocalDate.now();
            transferEndTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(transferStratTime) && StringUtils.isNotBlank(transferEndTime)){
            LocalDate startDate = LocalDate.parse(transferStratTime, dtf);
            LocalDate endDate = LocalDate.parse(transferEndTime, dtf);
            if(endDate.isBefore(startDate)){
                return "转账结束日期不能大于转账开始日期";
            }
            transferStratTime += " 00:00:00";
            transferEndTime += " 23:59:59";
        }

        if(StringUtils.isNotBlank(registrantStartTime) && StringUtils.isBlank(registrantEndTime)){
            LocalDate nowDate = LocalDate.now();
            registrantEndTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(registrantStartTime) && StringUtils.isNotBlank(registrantEndTime)){
            LocalDate startDate = LocalDate.parse(registrantStartTime, dtf);
            LocalDate endDate = LocalDate.parse(registrantEndTime, dtf);
            if(endDate.isBefore(startDate)){
                return "登记结束日期不能大于登记开始日期";
            }
            registrantStartTime += " 00:00:00";
            registrantEndTime += " 23:59:59";
        }
        return null;
    }
}
